package com.qcby.controller;

import com.qcby.common.ExamDetail.ExamSubmitRequest;
import com.qcby.entity.Exam;
import com.qcby.entity.QuestionBank;
import com.qcby.entity.Result;
import com.qcby.service.ExamDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/ExamDetail")
@Api(tags = "考试页面接口")
public class ExamDetailController {

    @Autowired
    ExamDetailService examDetailService;

    @PostMapping("/LoadExamInfo")
    @ApiOperation(value = "通过id加载考试信息")
    @ResponseBody
    public Result<Exam> loadExamInfo(int id){
        return examDetailService.loadExamInfo(id);
    }

    @PostMapping("/LoadMultipleChoiceQuestions")
    @ApiOperation(value = "加载选择题信息")
    @ResponseBody
    public Result<List<QuestionBank>> loadMultipleChoiceQuestions(int e_id){
        return examDetailService.loadMultipleChoiceQuestions(e_id);
    }

    @PostMapping("/LoadFillInTheBlankQuestions")
    @ApiOperation(value = "加载填空题信息")
    @ResponseBody
    public Result<List<QuestionBank>> loadFillInTheBlankQuestions(int e_id) {
        return examDetailService.loadFillInTheBlankQuestions(e_id);
    }

    @PostMapping("/LoadingTrueOrFalseQuestions")
    @ApiOperation(value = "加载判断题信息")
    @ResponseBody
    public Result<List<QuestionBank>> loadingTrueOrFalseQuestions(int e_id) {
        return examDetailService.loadingTrueOrFalseQuestions(e_id);
    }

    @PostMapping("/LoadShortAnswerQuestions")
    @ApiOperation(value = "加载解答题信息")
    @ResponseBody
    public Result<List<QuestionBank>> loadShortAnswerQuestions(int e_id) {
        return examDetailService.loadShortAnswerQuestions(e_id);
    }

    @PostMapping("/LoadingCalculationQuestions")
    @ApiOperation(value = "加载计算题信息")
    @ResponseBody
    public Result<List<QuestionBank>> loadingCalculationQuestions(int e_id) {
        return examDetailService.loadingCalculationQuestions(e_id);
    }

    @PostMapping("/SubmitToAI")
    @ApiOperation(value = "提交做题结果给ai判题")
    @ResponseBody
    public Result<Integer> submitToAI(@RequestBody ExamSubmitRequest request){
//        System.out.println("接收的考试 ID：" + request.getExam_id());
//        for (ExamSubmitRequest.QuestionDTO question : request.getQuestions()) {
//            System.out.println("题目 ID：" + question.getQuestion_id());
//            System.out.println("题型：" + question.getType());
//            System.out.println("题目内容：" + question.getQuestion());
//            System.out.println("用户答案：" + question.getUser_answer());
//            // 若有需要，还能处理 options 等字段
//        }
        Result<Integer> result = examDetailService.submitToAI(request);
        System.out.println(result);
        return result;
    }
}
